[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
vbcc
.
To execute code compiled by vbcc
, a library is needed. It
provides basic interfaces to the underlying operating system or
hardware as well as a set of often used functions.
A big part of the library is portable across all architectures. However, some functions (e.g. for input/output or memory allocation) are naturally dependent on the operating system or hardware. There are several sections in this chapter dealing with different versions of the library.
The library itself often is split into several parts. A startup-code will do useful initializations, like setting up IO, parsing the command line or initializing variables and hardware.
The biggest part of the functions will usually be stored in one library file. The name and format of this file depends on the conventions of the underlying system (e.g. `vc.lib' or `libvc.a').
Often, floating point code (if available) is stored in a different file (e.g. `m.lib' or `libm.a'). If floating point is used in an application, it might be necessary to explicitly link with this library (e.g. by specifying `-lm').
In many cases, the include files provide special inline-code or similar optimizations. Therefore, it is recommended to always include the corresponding include file when using a library function. Even if it is not necessary in all cases, it may affect the quality of the generated code.
The library implements the functions specified by ISO9899:1989 as well as a small number of the new functions from ISO9899:1999.
Most parts of this library are public domain. However, for some systems, parts may be under a different license. Please consult the system specific documentation. Usually, linking against this library will not put any restrictions on the created executable unless otherwise mentioned.
This section describes specifics of the C library for AmigaOS/68k. The relevant files are `startup.o', `minstart.o', `vc.lib', `vcs.lib', `mieee.lib', `m881.lib', `m040.lib', `amiga.lib', `amigas.lib', `extra.lib' and `extras.lib'.
The startup code currently consists of a slightly modified standard Amiga startup (`startup.o'). The startup code sets up some global variables and initializes stdin, stdout and stderr. The exit code closes all open files and frees all memory. If you link with a math library the startup/exit code will be taken from there if necessary.
Note that you have to link with a math library if you want to use floating point. All math functions, special startup code and printf/scanf functions which support floating point are contained in the math libraries only. At the moment there are three math libraries:
Depending on the CPU/FPU selected, #including `math.h' will cause inline-code generated for certain math functions.
An application can specify the stack-size needed by defining a variable
__stack
(of type size_t
) with external linkage, e.g.
size_t __stack=65536; /* 64KB stack-size */ |
The startup code will check whether the stack-size specified is larger than the default stack-size (as set in the shell) and switch to a new stack of appropriate size, if necessary.
If the `-stack-check' option is specified when compiling, the library will check for a stack overflow and abort the program, if the stack overflows. Note, however, that only code compiled with this option will be checked. Calls to libraries which have not been compiled with `-stack-check' or calls to OS function may cause a stack overflow which is not noticed.
Additionally, if `-stack-check' is used, the maximum stack-size
used can be read by querying the external variable __stack_usage
.
#include <stdio.h> extern size_t __stack_usage; main() { do_program(); printf("stack used: %lu\n",(unsigned long)__stack_usage); } |
Like above, the stack used by functions not compiled using `-stack-check' or OS functions is ignored.
When using the small data model of the 68k series CPUs, you also have to link with appropriate libraries. Most libraries documented here are also available as small data versions (with an 's' attached to the file name). Exceptions are the math libraries.
To compile and link a program using the small data model a command like
vc test.c -o test -sd -lvcs -lamigas |
might be used.
The following list contains some restrictions of this version of the library:
tmpfile()
tmpfile()
function always returns an error.
clock()
clock()
function always returns -1. This is correct,
according to the C standard, because on AmigaOS it is not possible to
obtain the time used by the calling process. For programs which cannot
deal with this, a special version of clock()
is provided in
`extra.lib' (See section 7.3.9 extra.lib).
If you want to write programs that use only Amiga functions and none from
vc.lib you can use `minstart.o' instead of `startup.o' and
produce smaller executables.
This is only useful for people who know enough about the Amiga shared
libraries, the stubs in amiga.lib etc. If you do not know enough about
those things better forget minstart at all.
This startup code does not set up all the things needed by vc.lib, so you
must not use most of those functions (string and ctype funtions are ok,
but most other functions - especially I/O and memory handling - must not
be used).
exit()
is supplied by minstart and can be used.
The command line is not parsed, but passed to main()
as a single
string,
so you can declare main as
int main(char *command)
or int main(void)
.
Also no Amiga libraries are opened (but SysBase
ist set up), so you
have to define and open DOSBase
yourself if you need it.
If you want to use floating point with the IEEE libraries you have to
define and open MathIeeeSingBas.library, MathIeeeDoubBas.library and
MathIeeeDoubTrans.library (in this order!) and link with mieee.lib (if
compiled for FPU this is not needed).
A hello world using minstart could look like this:
#include <exec/libraries.h> #include <clib/exec_protos.h> #include <clib/dos_protos.h> struct Library *DOSBase; main() { if(DOSBase=OpenLibrary("dos.library",0)){ Write(Output(),"Hello, world!\n",14); CloseLibrary(DOSBase); } return 0; } |
This can yield an executable of under 300 bytes when compiled with
`-sc -sd -O2' and linked with `minstart.o' and amigas.lib
(using vlink
- may not work with other linkers).
To write programs accessing AmigaOS (rather than standard C functions
only), a replacement for the original (copyrighted) `amiga.lib'
is provided with vbcc
. This replacement is adapted to vbcc,
does not cause collisions with some functions (e.g. sprintf
)
provided by the original `amiga.lib' and is available in
small data. It is recommended to always use this library rather than
the original version.
Additionally, there are header files (in the `proto'- and `inline'-subdirectories) which cause inlined calls to Amiga library functions.
For AmigaOS/68k, `amiga.lib' is linked by default.
To link with `auto.lib' (or the small data version
`autos.lib') specify
the `-lauto' or `-lautos' option to vc
.
When you are calling a standard Amiga library function and do not
have defined the corresponding library base then the library base
as well as code to open/close it will be taken from `auto.lib'.
By default, `auto.lib' will try to open any library version. If you
need at least a certain version you can define and set a variable
_<library-base>Ver with external linkage, e.g. (on file-scope):
int _IntuitionBaseVer = 39; |
Note that your program will abort before reaching main()
if one
of the libraries cannot be opened. Also note that the dos.library
will be openened by the standard startup code, not by auto.lib.
This means you have to open dos.library yourself, when linking
with `minstart.o'.
To link with `extra.lib' (or the small data version
`extras.lib'), specify `-lextra' or `-lextras' to
vc
.
There is also a header file `extra.h'.
At the moment extra.lib contains the following functions:
getch()
getchar()
but sets the console to raw mode
and does not wait for return.
stricmp()
strcmp()
.
strnicmp()
strncmp()
.
chdir()
clock()
clock()
function
in `vc.lib'. clock()
is supposed to return the
amount of
cpu-time spent by the current program. As this is
generally not possible on the Amiga clock()
from
`vc.lib' always returns -1.
However there seem to be several badly written
programs that do not check this. So this version
of clock()
returns values which are strictly ascending
for successive calls to clock()
and the difference
between them is the time difference between the calls.
iswhitespace()
isspace()
.
isseparator()
ixemul.library is a shared Amiga library which is covered by the GNU license and includes standard ANSI and POSIX functions as well as some functions common in Unix, BSD and similar operating systems. Have a look at the ixemul-archives if you want to find out more. The link library ixemul.lib provided with vbcc only contains stub functions which call the functions in the shared library plus some auxiliary functions for vbcc. What are the main differences between vc.lib and ixemul.lib?
Things you should note:
vc +ixemul hello.c |
The small data model is currently not supported with `ixemul.lib',
but the small code model is.
If your program needs a certain version of the ixemul.library you can
define a variable __ixemulVer
with external linkage which specifies
the minimum required version, e.g.
int __ixemulVer = 45; |
This section describes specifics of the C library for PowerUp/PPC. The relevant files are `startup.o', `minstart.o', `libvc.a', `libvcs.a', `libm.a', `libamiga.a', `libamigas.a', `libextra.a' and `libextras.a'.
The math library (`libm.a') is linked against the floating point library libmoto by Motorola.
Depending on the CPU/FPU selected, #including `math.h' will cause inline-code generated for certain math functions.
Stack-handling is similar to AmigaOS/68k (See section 7.3.3 Stack).
The only difference is that stack-swapping cannot be done. If the
default stack-size is less than the stack-size specified with
__stack
the program will abort.
vc test.c -o test -sd -lvcs -lamigas |
tmpfile()
tmpfile()
function always returns an error.
clock()
clock()
function always returns -1. This is correct,
according to the C standard, because on AmigaOS it is not possible to
obtain the time used by the calling process. For programs which cannot
deal with this, a special version of clock()
is provided in
`extra.lib' (See section 7.3.9 extra.lib).
The provided minimal startup code (`minstart.o') is used similarly like the one for 68k (See section 7.3.6 Minimal startup). Only use it if you know what you are doing.
vbcc
. This replacement (`libamiga.a')
automatically performs a necessary context switch to the 68k to execute
the system call. Furthermore, it is adapted to vbcc,
does not cause collisions with some functions (e.g. sprintf
)
provided by the original `amiga.lib' and is available in
small data.
Specify `-lamiga' to link with `libamiga.a'.
This library corresponds to the AmigaOS/68k version (See section 7.3.9 extra.lib).
The math library (`m.lib') contains functions from Sun's
portable floating point library. Additionally, there is a
vbcc
version of Andreas Heumann's `ppcmath.lib'.
These routines are linked against Motorola's floating point
routines optimized for PowerPC and therefore are much faster.
To make use of this library, link with `ppcmath.lib' before `m.lib', e.g.
vc test.c -lppcmath -lm |
Depending on the CPU/FPU selected, #including `math.h' will cause inline-code generated for certain math functions.
Stack-handling is similar to AmigaOS/68k (See section 7.3.3 Stack).
tmpfile()
tmpfile()
function always returns an error.
clock()
clock()
function always returns -1. This is correct,
according to the C standard, because on AmigaOS it is not possible to
obtain the time used by the calling process. For programs which cannot
deal with this, a special version of clock()
is provided in
`extra.lib' (See section 7.3.9 extra.lib).
vbcc
. This replacement
automatically performs a necessary context switch to the 68k to execute
the system call. Furthermore, it is adapted to vbcc,
does not cause collisions with some functions (e.g. sprintf
)
provided by the original `amiga.lib' and is available in
small data.
Specify `-lamiga' to link with `amiga.lib'.
Stack-handling is similar to AmigaOS/68k (See section 7.3.3 Stack).
vc test.c -o test -sd -lvcs -lamigas |
tmpfile()
tmpfile()
function always returns an error.
clock()
clock()
function always returns -1. This is correct,
according to the C standard, because on MorphOS it is not possible to
obtain the time used by the calling process. For programs which cannot
deal with this, a special version of clock()
is provided in
`extra.lib' (See section 7.3.9 extra.lib).
To write programs using AmigaOS compatible functions, a replacement for
the original (copyrighted) `amiga.lib'
is provided with vbcc
. This replacement (`libamiga.a')
will invoke the MorphOS 68k emulator to execute the system function.
Furthermore, it is adapted to vbcc and
does not cause collisions with some functions (e.g. sprintf
)
and is available in small data.
Specify `-lamiga' to link with `libamiga.a'.
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |